package com.newtouch.bxzs.common.base.response;

import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseErrorInfoInterface;

/**
 * 接口controller统一出参类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月11日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
public class RespGenerator {
	/**
	 * 接口调用成功时出参
	 * 
	 * @param data
	 *            接口返回数据
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static BaseResponse returnOK(Object data) {
		return new BaseResponse(BaseErrorEnum.SUCCESS.getResultCode(), "接口调用成功!", data);
	}

	/**
	 * 调用失败
	 * 
	 * @param errorInfo
	 *            错误返回码
	 * @return
	 */
	public static BaseResponse<Object> returnError(BaseErrorInfoInterface errorInfo) {
		return new BaseResponse<Object>(errorInfo.getResultCode(), errorInfo.getResultMsg(), null);
	}

	/**
	 * 调用失败
	 * 
	 * @param code
	 *            错误码
	 * @param message
	 *            错误信息
	 * @return
	 */
	public static BaseResponse<Object> returnError(String code, String message) {
		return new BaseResponse<Object>(code, message, null);
	}

	/**
	 * 调用失败
	 * 
	 * @param message
	 *            错误信息
	 * @return
	 */
	public static BaseResponse<Object> returnError(String message) {
		return new BaseResponse<Object>("-1", message, null);
	}

}
